window.onload = function () {
  search();
  secondKill();
};
/*头部搜索*/
var search = function () {
  var search = document.getElementsByClassName('jd_header_box')[0];
  var banner = document.getElementsByClassName('jd_banner')[0];
  var height = banner.offsetHeight;
  window.onscroll = function () {
    // top
    var top = document.body.scrollTop;
    /*当滚动高度大于banner高度颜色不变*/
    if (top > height) {
      search.style.background = "rgba(201,21,35,0.85)";
    } else {
      var op = top / height * 0.85 == 0 ? 0.85 : top / height * 0.85;
      search.style.background = "rgba(201,21,35," + op + ")";
    }
  }
};
/*秒杀倒计时*/
var secondKill = function () {
  // 父盒子
  var parentTime = document.getElementsByClassName('sk_time')[0];
  /*span时间*/
  var timeList = parentTime.getElementsByClassName('num');

  var times = 4 * 60 * 60;
  console.log(times);
  setInterval(function () {
    times--;
    var hours = Math.floor(times / (60 * 60));
    var minutes = Math.floor(times / 60 % 60);
    var seconds = times % 60;
    console.log(hours);
    console.log(minutes);
    console.log(seconds);
    timeList[0].innerHTML = hours > 10 ? Math.floor(hours / 10) : 0;
    timeList[1].innerHTML = hours % 10;

    timeList[2].innerHTML = minutes > 10 ? Math.floor(minutes / 10) : 0;
    timeList[3].innerHTML = minutes % 10;

    timeList[4].innerHTML = seconds > 10 ? Math.floor(seconds / 10) : 0;
    timeList[5].innerHTML = seconds % 10;

  }, 1000);
};
